<?php
function sessionize_inputs(){
	foreach($_POST as $name => $value){
		if(!empty($_POST[$name])){
			$_SESSION[$name] = $value;
		}
	}
}

function is_email($email){
	if(preg_match("/^[a-zA-Z0-9\.\-\_]*@[a-zA-Z0-9\.\-\_]*$/",$email,$matches)){
		return true;
	}else{
		return false;
	}
}

function replace_session($buff){
	if(preg_match_all("/{(.+)}/",$buff,$matches)){
		foreach($matches[0] as $match=>$value){
			if($_SESSION[$matches[1][$match]]){
				if(substr($matches[0][$match],0,2) !== '{='){
					$buff=str_replace($matches[0][$match],$_SESSION[$matches[1][$match]],$buff);
				}
				if($_SESSION['db_pass']==''){
					$buff=str_replace('{db_pass}','',$buff);
				}
			}
		}
		return $buff;
	}
}

function language_select(){
	$dir = opendir('./lang');
	while (($lang = readdir($dir)) !== false) {
		if($lang !== '.' && $lang !== '..'){
			echo '<option value="'.$lang.'">'.$lang.'</option>';
		}
	}
}

?>
